package com.abetsy.vben.api;

import com.abetsy.vben.param.DramaDetailsParam;
import com.abetsy.vben.param.DramaSearchParam;
import com.abetsy.vben.param.DramaSharePreviewParam;
import com.abetsy.vben.param.ShareDramaListParam;
import com.abetsy.vben.param.ShareDramaParam;
import com.abetsy.vben.service.TMDBService;
import com.abetsy.vben.utils.api.ResultData;
import com.abetsy.vben.vo.DramaDetailsVo;
import com.abetsy.vben.vo.DramaVo;
import com.abetsy.vben.vo.ShareDramaInfoVo;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * TMDB资源代理
 */
@RestController
@RequestMapping("/tmdb")
@CrossOrigin(origins = "*")
public class TMDBController {

    @Resource
    private TMDBService tmdbService;

    /**
     * 图片代理
     */
    @GetMapping("/image/{imagePath}")
    public ResponseEntity<byte[]> proxyImage(@PathVariable String imagePath) {
        return tmdbService.proxyImage(imagePath);
    }

    /**
     * Drama搜索代理
     */
    @PostMapping("/drama/search")
    public ResultData<List<DramaVo>> searchDrama(@RequestBody @Validated DramaSearchParam param, HttpServletRequest request) {
        return ResultData.success(tmdbService.searchDrama(param.getDramaName(), request));
    }

    /**
     * Drama详情
     */
    @PostMapping("/drama/details")
    public ResultData<DramaDetailsVo> dramaDetails(@RequestBody @Validated DramaDetailsParam param, HttpServletRequest request) {
        return ResultData.success(tmdbService.dramaDetails(param.getId(), request));
    }

    /**
     * Drama资源预览
     */
    @PostMapping("/drama/preview")
    public ResultData<ShareDramaInfoVo> dramaPreview(@RequestBody @Validated DramaSharePreviewParam param) {
        return ResultData.success(tmdbService.dramaPreview(param));
    }

    /**
     * Drama资源保存
     */
    @PostMapping("/drama/share")
    public ResultData<Object> dramaShare(@RequestBody @Validated ShareDramaParam param) {
        return ResultData.success(tmdbService.dramaShare(param));
    }

    /**
     * Drama资源列表
     */
    @PostMapping("/drama/list")
    public ResultData<Object> dramaList(@RequestBody @Validated ShareDramaListParam param) {
        return ResultData.success(tmdbService.dramaList(param));
    }

}
